<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wcs__locate}">
      <wcs-form v-model="dataForm" :formList="formList" :table-column="tableColumn" :advanced="advanced"
        @check-change="checkChange" @changeAdvance="changeAdvance" @getDataList="getDataList" @getReset="getReset">
        <el-form-item>
          <el-button v-if="$hasPermission('wcs:trk:operate')" size="small" type="warning" @click="wcsTrkHandle('CANCEL')">{{
            "任务取消"
            }}</el-button>
          <el-button v-if="$hasPermission('wcs:trk:operate')" size="small" type="danger" @click="wcsTrkHandle('DELETE')">{{
            "任务删除"
            }}</el-button>
        </el-form-item>
      </wcs-form>
      <wcs-table ref="wcsTable" class="trkTable" v-model="dataForm" :page="page" :total="total" :limit="limit"
        :tableData="dataList" :table-column="column" :module-options="mixinViewModuleOptions"
        :dataListLoading="dataListLoading" :showSelection="true" @pageSizeChangeHandle="pageSizeChangeHandle"
        @pageCurrentChangeHandle="pageCurrentChangeHandle" @selectChangeHandle="selectChangeHandle" />
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import debounce from "lodash/debounce";
import { formList, tableColumn } from "./config";
import wcsTable from "@/components/wcs-table";
import wcsForm from "@/components/wcs-form";
import { trkHandle } from "@/utils/api";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wcs/trk/page",
        getDataListIsPage: true,
      },
      dataForm: {
        pkId: "",
        dvcNo: "",
        contNo: "",
        frmPos: "",
        toPos: "",
        trkType: "",
      },
      trkId: "",
      formList,
      tableColumn,
      column: [],
      advanced: false,
    };
  },
  components: {
    wcsTable,
    wcsForm,
  },
  methods: {
    //0.重置搜索框
    getReset() {
      this.dataForm = this.$options.data().dataForm;
    },
    wcsTrkHandle(operateType) {
      if (!this.trkId) {
        return this.$message({
          message: "请先选择任务！",
          type: "warning",
          duration: 500,
        });
      }
      this.$confirm(`是否确认对任务ID[${this.trkId}]进行[${operateType}]操作?`, this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(()=>{
        const params = {
        trkId: this.trkId,
        operateType,
      };
      trkHandle(params).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.$message({
          message: res.data,
          type: "success",
          duration: 3000,
          onClose: () => {
            this.getDataList();
          },
        });
      });
      }).catch(()=>{})
    },
    // 单选
    selectChangeHandle(selection, row) {
      this.trkId = ""; //每次单选都重置id
      if (selection.length > 1) {
        this.$refs.wcsTable.$refs.Table.clearSelection();
        this.$refs.wcsTable.$refs.Table.toggleRowSelection(row);
      }
      if (selection.length != 0) {
        //只有当真正选中了目标主单才获取id
        this.trkId = row.trkId;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
/* 隐藏表头的全选框 */
::v-deep .trkTable thead .el-table-column--selection .cell {
  display: none;
}
</style>
<style>
.right-handle-group {
  float: right;
}
</style>
